Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert FixedOffset::{east, west} to return Result #1468

Merged
merged 1 commit into from
Feb 28, 2024

Conversation

pitdicker
Copy link
Collaborator

The easiest methods to convert yet!

Both Error::InvalidArgument and Error::OutOfRange could be reasonable return types.

The real-world limit of offsets is currently 14 hours, which puts area's using it 2 hours to the other side of the international date line.
The type limit is generous and somewhat arbitrarily limited to be less than 24 hours. At some point it turned out limiting the offset to less than a day keeps the surrounding code saner.

Because the limit is artificial and specific to chrono I went with Error::OutOfRange.

cc @Zomtir.

@pitdicker pitdicker force-pushed the convert_fixed_offset branch from 837d1ab to 68d9e3e Compare February 28, 2024 13:16
Copy link

codecov bot commented Feb 28, 2024

Codecov Report

Attention: Patch coverage is 71.42857% with 4 lines in your changes are missing coverage. Please review.

Project coverage is 94.34%. Comparing base (f0e6695) to head (68d9e3e).
Report is 2 commits behind head on 0.5.x.

Files Patch % Lines
src/offset/fixed.rs 80.00% 2 Missing ⚠️
src/format/parsed.rs 50.00% 1 Missing ⚠️
src/offset/local/unix.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##            0.5.x    #1468      +/-   ##
==========================================
+ Coverage   94.33%   94.34%   +0.01%     
==========================================
  Files          37       37              
  Lines       17004    17009       +5     
==========================================
+ Hits        16040    16047       +7     
+ Misses        964      962       -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@pitdicker
Copy link
Collaborator Author

The spelling of the existing docs doesn't seems entirely correct English. I'll adjust that.

let fixed_offset = FixedOffset::east(secs)
.expect("Could not generate a valid chrono::FixedOffset. It looks like implementation of Arbitrary for FixedOffset is erroneous.");
Ok(fixed_offset)
Ok(FixedOffset::east(secs).unwrap())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could the unwrapping be prevented by mapping the error? Untested: FixedOffset::east(secs).or(Err(arbitrary::Error))

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The range we supply to arbitrary::Unstructured::int_in_range is exactly equal to the range FixedOffset supports, and I don't see that changing. This should simply never fail, so I even considered the expect to be overkill.

} else {
None
pub const fn east(secs: i32) -> Result<FixedOffset, Error> {
match -86_400 < secs && secs < 86_400 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I appreciate the conversion to match, in the future I would appreciate it more in a separate commit. 👍

@pitdicker pitdicker merged commit 999582e into chronotope:0.5.x Feb 28, 2024
34 of 35 checks passed
@pitdicker pitdicker deleted the convert_fixed_offset branch February 28, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants